﻿(function ($) {
    $.learuntab = {
        requestFullScreen: function () {
            var de = document.documentElement;
            if (de.requestFullscreen) {
                de.requestFullscreen();
            } else if (de.mozRequestFullScreen) {
                de.mozRequestFullScreen();
            } else if (de.webkitRequestFullScreen) {
                de.webkitRequestFullScreen();
            }
        },
        exitFullscreen: function () {
            var de = document;
            if (de.exitFullscreen) {
                de.exitFullscreen();
            } else if (de.mozCancelFullScreen) {
                de.mozCancelFullScreen();
            } else if (de.webkitCancelFullScreen) {
                de.webkitCancelFullScreen();
            }
        },
        refreshTab: function () {
            var currentId = $('.page-tabs-content').find('.active').attr('data-id');
            var target = $('.LRADMS_iframe[data-id="' + currentId + '"]');
            var url = target.attr('src');
            //$.loading(true);
            target.attr('src', url).load(function () {
                //$.loading(false);
            });
        },
        activeTab: function () {
            var currentId = $(this).data('id');
            if (!$(this).hasClass('active')) {
                $('.mainContent .LRADMS_iframe').each(function () {
                    if ($(this).data('id') == currentId) {
                        console.log($(this).data('id'))
                        $(this).show().siblings('.LRADMS_iframe').hide();
                        return false;
                    }
                });
                $(this).addClass('active').siblings('.menuTab').removeClass('active');
                $.learuntab.scrollToTab(this);
            }
        },
        closeOtherTabs: function () {
            $('.page-tabs-content').children("[data-id]").find('.fa-remove').parents('a').not(".active").each(function () {
                $('.LRADMS_iframe[data-id="' + $(this).data('id') + '"]').remove();
                $(this).remove();
            });
            $('.page-tabs-content').css("margin-left", "0");
        },
        closeTab: function () {
            var closeTabId = $(this).parents('.menuTab').data('id');
            var currentWidth = $(this).parents('.menuTab').width();
            if ($(this).parents('.menuTab').hasClass('active')) {
                if ($(this).parents('.menuTab').next('.menuTab').size()) {
                    var activeId = $(this).parents('.menuTab').next('.menuTab:eq(0)').data('id');
                    $(this).parents('.menuTab').next('.menuTab:eq(0)').addClass('active');

                    $('.mainContent .LRADMS_iframe').each(function () {
                        if ($(this).data('id') == activeId) {
                            $(this).show().siblings('.LRADMS_iframe').hide();
                            return false;
                        }
                    });
                    var marginLeftVal = parseInt($('.page-tabs-content').css('margin-left'));
                    if (marginLeftVal < 0) {
                        $('.page-tabs-content').animate({
                            marginLeft: (marginLeftVal + currentWidth) + 'px'
                        }, "fast");
                    }
                    $(this).parents('.menuTab').remove();
                    $('.mainContent .LRADMS_iframe').each(function () {
                        if ($(this).data('id') == closeTabId) {
                            $(this).remove();
                            return false;
                        }
                    });
                }
                if ($(this).parents('.menuTab').prev('.menuTab').size()) {
                    var activeId = $(this).parents('.menuTab').prev('.menuTab:last').data('id');
                    $(this).parents('.menuTab').prev('.menuTab:last').addClass('active');
                    $('.mainContent .LRADMS_iframe').each(function () {
                        if ($(this).data('id') == activeId) {
                            $(this).show().siblings('.LRADMS_iframe').hide();
                            return false;
                        }
                    });
                    $(this).parents('.menuTab').remove();
                    $('.mainContent .LRADMS_iframe').each(function () {
                        if ($(this).data('id')== closeTabId) {
                            $(this).remove();
                            return false;
                        }
                    });
                }
            }
            else {

                $(this).parents('.menuTab').remove();
                $('.mainContent .LRADMS_iframe').each(function () {
                    if ($(this).data('id') == closeTabId) {
                        $(this).remove();
                        return false;
                    }
                });
                $.learuntab.scrollToTab($('.menuTab.active'));
            }
            return false;
        },
        addTab: function () {
            $(".navbar-custom-menu>ul>li.open").removeClass("open");
            var dataId = $(this).attr('data-id');
            if (dataId != "") {
                //top.$.cookie('nfine_currentmoduleid', dataId, { path: "/" });
            }
            var dataUrl = $(this).attr('href');
            var menuName = $.trim($(this).text());
            var flag = true;
            if (dataUrl == undefined || $.trim(dataUrl).length == 0) {
                return false;
            }
            $('.menuTab').each(function () {
                if ($(this).data('id') == dataUrl) {
                    if (!$(this).hasClass('active')) {
                        $(this).addClass('active').siblings('.menuTab').removeClass('active');
                        $.learuntab.scrollToTab(this);
                        $('.mainContent .LRADMS_iframe').each(function () {
                            if ($(this).data('id') == dataUrl) {
                                $(this).show().siblings('.LRADMS_iframe').hide();
                                return false;
                            }
                        });
                    }
                    flag = false;
                    return false;
                }
            });
            if (flag) {
                var str = '<a href="javascript:;" class="active menuTab" data-id="' + dataUrl + '">' + menuName + ' <i class="fa fa-remove"></i></a>';
                $('.menuTab').removeClass('active');
                var str1 = '<iframe class="LRADMS_iframe" id="iframe' + dataId + '" width="100%" height="100%" data-id="' + dataUrl + '" src="' + dataUrl + '" frameborder="0"></iframe>';
                $('.mainContent').find('iframe.LRADMS_iframe').hide();
                $('.mainContent').append(str1);
                //$.loading(true);
                $('.mainContent iframe:visible').load(function () {
                    //$.loading(false);
                });
                $('.menuTabs .page-tabs-content').append(str);
                $.learuntab.scrollToTab($('.menuTab.active'));
            }
            return false;
        },
        scrollTabRight: function () {
            var marginLeftVal = Math.abs(parseInt($('.page-tabs-content').css('margin-left')));
            var tabOuterWidth = $.learuntab.calSumWidth($(".content-tabs").children().not(".menuTabs"));
            var visibleWidth = $(".content-tabs").outerWidth(true) - tabOuterWidth;
            var scrollVal = 0;
            if ($(".page-tabs-content").width() < visibleWidth) {
                return false;
            } else {
                var tabElement = $(".menuTab:first");
                var offsetVal = 0;
                while ((offsetVal + $(tabElement).outerWidth(true)) <= marginLeftVal) {
                    offsetVal += $(tabElement).outerWidth(true);
                    tabElement = $(tabElement).next();
                }
                offsetVal = 0;
                while ((offsetVal + $(tabElement).outerWidth(true)) < (visibleWidth) && tabElement.length > 0) {
                    offsetVal += $(tabElement).outerWidth(true);
                    tabElement = $(tabElement).next();
                }
                scrollVal = $.learuntab.calSumWidth($(tabElement).prevAll());
                if (scrollVal > 0) {
                    $('.page-tabs-content').animate({
                        marginLeft: 0 - scrollVal + 'px'
                    }, "fast");
                }
            }
        },
        scrollTabLeft: function () {
            var marginLeftVal = Math.abs(parseInt($('.page-tabs-content').css('margin-left')));
            var tabOuterWidth = $.learuntab.calSumWidth($(".content-tabs").children().not(".menuTabs"));
            var visibleWidth = $(".content-tabs").outerWidth(true) - tabOuterWidth;
            var scrollVal = 0;
            if ($(".page-tabs-content").width() < visibleWidth) {
                return false;
            } else {
                var tabElement = $(".menuTab:first");
                var offsetVal = 0;
                while ((offsetVal + $(tabElement).outerWidth(true)) <= marginLeftVal) {
                    offsetVal += $(tabElement).outerWidth(true);
                    tabElement = $(tabElement).next();
                }
                offsetVal = 0;
                if ($.learuntab.calSumWidth($(tabElement).prevAll()) > visibleWidth) {
                    while ((offsetVal + $(tabElement).outerWidth(true)) < (visibleWidth) && tabElement.length > 0) {
                        offsetVal += $(tabElement).outerWidth(true);
                        tabElement = $(tabElement).prev();
                    }
                    scrollVal = $.learuntab.calSumWidth($(tabElement).prevAll());
                }
            }
            $('.page-tabs-content').animate({
                marginLeft: 0 - scrollVal + 'px'
            }, "fast");
        },
        scrollToTab: function (element) {
            var marginLeftVal = $.learuntab.calSumWidth($(element).prevAll()), marginRightVal = $.learuntab.calSumWidth($(element).nextAll());
            var tabOuterWidth = $.learuntab.calSumWidth($(".content-tabs").children().not(".menuTabs"));
            var visibleWidth = $(".content-tabs").outerWidth(true) - tabOuterWidth;
            var scrollVal = 0;
            if ($(".page-tabs-content").outerWidth() < visibleWidth) {
                scrollVal = 0;
            } else if (marginRightVal <= (visibleWidth - $(element).outerWidth(true) - $(element).next().outerWidth(true))) {
                if ((visibleWidth - $(element).next().outerWidth(true)) > marginRightVal) {
                    scrollVal = marginLeftVal;
                    var tabElement = element;
                    while ((scrollVal - $(tabElement).outerWidth()) > ($(".page-tabs-content").outerWidth() - visibleWidth)) {
                        scrollVal -= $(tabElement).prev().outerWidth();
                        tabElement = $(tabElement).prev();
                    }
                }
            } else if (marginLeftVal > (visibleWidth - $(element).outerWidth(true) - $(element).prev().outerWidth(true))) {
                scrollVal = marginLeftVal - $(element).prev().outerWidth(true);
            }
            $('.page-tabs-content').animate({
                marginLeft: 0 - scrollVal + 'px'
            }, "fast");
        },
        calSumWidth: function (element) {
            var width = 0;
            $(element).each(function () {
                width += $(this).outerWidth(true);
            });
            return width;
        },
        init: function () {
            $('.menuItem').on('click', $.learuntab.addTab);
            $('.menuTabs').on('click', '.menuTab i', $.learuntab.closeTab);
            $('.menuTabs').on('click', '.menuTab', $.learuntab.activeTab);
            $('.tabLeft').on('click', $.learuntab.scrollTabLeft);
            $('.tabRight').on('click', $.learuntab.scrollTabRight);
            $('.tabReload').on('click', $.learuntab.refreshTab);
            $('.tabCloseCurrent').on('click', function () {
                $('.page-tabs-content').find('.active i').trigger("click");
            });
            $('.tabCloseAll').on('click', function () {
                $('.page-tabs-content').children("[data-id]").find('.fa-remove').each(function () {
                    $('.LRADMS_iframe[data-id="' + $(this).data('id') + '"]').remove();
                    $(this).parents('a').remove();
                });
                $('.page-tabs-content').children("[data-id]:first").each(function () {
                    $('.LRADMS_iframe[data-id="' + $(this).data('id') + '"]').show();
                    $(this).addClass("active");
                });
                $('.page-tabs-content').css("margin-left", "0");
            });
            $('.tabCloseOther').on('click', $.learuntab.closeOtherTabs);
            $('.fullscreen').on('click', function () {
                if (!$(this).attr('fullscreen')) {
                    $(this).attr('fullscreen', 'true');
                    $.learuntab.requestFullScreen();
                } else {
                    $(this).removeAttr('fullscreen')
                    $.learuntab.exitFullscreen();
                }
            });
        }
    };

    /********************************************************************************
    * 功能：加载结果数据
     * 函数：learunindex.load  learunindex.jsonWhere learunindex.loadMenu
     ********************************************************************************/
    $.learunindex = {
        load: function () {
            $("body").removeClass("hold-transition")
            $("#content-wrapper").find('.mainContent').height($(window).height() - 100);
            $(window).resize(function (e) {
                $("#content-wrapper").find('.mainContent').height($(window).height() - 100);
            });
            $(".sidebar-toggle").click(function () {
            	console.log("456")
                if (!$("body").hasClass("sidebar-collapse")) {
                    $("body").addClass("sidebar-collapse");
                } else {
                    $("body").removeClass("sidebar-collapse");
                }
            })
            $(window).load(function () {
                window.setTimeout(function () {
                    $('#ajax-loader').fadeOut();
                }, 300);
            });
        },
        jsonWhere: function (data, action) {
            if (action == null) return;
            var reval = new Array();
            $(data).each(function (i, v) {
                if (action(v)) {
                    reval.push(v);
                }
            })
            return reval;
        },
        loadMenu: function () {
            var data = [
            /************************************************
             * 级别：第一级菜单
             ************************************************/
                {
                    "F_ModuleId": "a1",
                    "F_ParentId": "0",
                    "F_EnCode": "SysManage",
                    "F_FullName": "登录注册行为分析",
                    "F_Icon": "fa fa-home",
                    "F_UrlAddress": "./dataHtml/login/loginPeople",
                    "F_Target": "expand",
                    "F_IsMenu": 0,
                    "F_AllowExpand": 0,
                    "F_IsPublic": 0,
                    "F_AllowEdit": null,
                    "F_AllowDelete": null,
                    "F_SortCode": 5,
                    "F_DeleteMark": 0,
                    "F_EnabledMark": 1,
                    "F_Description": null,
                    "F_CreateDate": "2015-12-22 16:42:12",
                    "F_CreateUserId": "System"
                },
                
//              {
//                  "F_ModuleId": "a2",
//                  "F_ParentId": "0",
//                  "F_EnCode": "BaseManage",
//                  "F_FullName": "学习行为分析",
//                  "F_Icon": "fa fa-comment",
//                  "F_UrlAddress": null,
//                  "F_Target": "expand",
//                  "F_IsMenu": 0,
//                  "F_AllowExpand": 1,
//                  "F_IsPublic": 0,
//                  "F_AllowEdit": null,
//                  "F_AllowDelete": null,
//                  "F_SortCode": 2,
//                  "F_DeleteMark": 0,
//                  "F_EnabledMark": 1,
//                  "F_Description": null,
//                  "F_CreateDate": null,
//                  "F_CreateUserId": null,
//                  "F_CreateUserName": null
//              },
                {
                    "F_ModuleId": "a3",
                    "F_ParentId": "0",
                    "F_EnCode": "FlowManage",
                    "F_FullName": "功能使用行为分析",
                    "F_Icon": "fa fa-share-alt-square",
                    "F_UrlAddress": null,
                    "F_Target": "expand",
                    "F_IsMenu": 0,
                    "F_AllowExpand": 1,
                    "F_IsPublic": 0,
                    "F_AllowEdit": null,
                    "F_AllowDelete": null,
                    "F_SortCode": 3,
                    "F_DeleteMark": 0,
                    "F_EnabledMark": 1,
                    "F_Description": null,
                    "F_CreateDate": null,
                    "F_CreateUserId": null,
                    "F_CreateUserName": null
                },
//              {
//                  "F_ModuleId": "4",
//                  "F_ParentId": "0",
//                  "F_EnCode": "CommonInfo",
//                  "F_FullName": "推广渠道效度分析",
//                  "F_Icon": "fa fa-pie-chart",
//                  "F_UrlAddress": null,
//                  "F_Target": "expand",
//                  "F_IsMenu": 0,
//                  "F_AllowExpand": 1,
//                  "F_IsPublic": 0,
//                  "F_AllowEdit": null,
//                  "F_AllowDelete": null,
//                  "F_SortCode": 5,
//                  "F_DeleteMark": 0,
//                  "F_EnabledMark": 1,
//                  "F_Description": null,
//                  "F_CreateDate": null,
//                  "F_CreateUserId": null,
//                  "F_CreateUserName": null
//              },
//
//              {
//                  "F_ModuleId": "5",
//                  "F_ParentId": "0",
//                  "F_EnCode": "CustomerManage",
//                  "F_FullName": "答疑社区",
//                  "F_Icon": "fa fa-comments",
//                  "F_UrlAddress": null,
//                  "F_Target": "expand",
//                  "F_IsMenu": 0,
//                  "F_AllowExpand": 1,
//                  "F_IsPublic": 0,
//                  "F_AllowEdit": null,
//                  "F_AllowDelete": null,
//                  "F_SortCode": 6,
//                  "F_DeleteMark": 0,
//                  "F_EnabledMark": 1
//              },
                {
                    "F_ModuleId": "6",
                    "F_ParentId": "0",
                    "F_EnCode": "CustomerManage",
                    "F_FullName": "学习行为分析",
                    "F_Icon": "fa fa-comment-o",
                    "F_UrlAddress": null,
                    "F_Target": "",
                    "F_IsMenu": 0,
                    "F_AllowExpand": 1,
                    "F_IsPublic": 0,
                    "F_AllowEdit": null,
                    "F_AllowDelete": null,
                    "F_SortCode": 6,
                    "F_DeleteMark": 0,
                    "F_EnabledMark": 1
                },
                {
                    "F_ModuleId": "7",
                    "F_ParentId": "0",
                    "F_EnCode": "CustomerManage",
                    "F_FullName": "推广效度分析",
                    "F_Icon": "fa fa-chain",
                    "F_UrlAddress": null
                },
                {
                    "F_ModuleId": "8",
                    "F_ParentId": "0",
                    "F_EnCode": "CustomerManage",
                    "F_FullName": "运营分析",
                    "F_Icon": "fa fa-mortar-board",
                    "F_UrlAddress": null
                },
                {
                    "F_ModuleId": "9",
                    "F_ParentId": "0",
                    "F_EnCode": "CustomerManage",
                    "F_FullName": "面审答辩使用情况",
                    "F_Icon": "fa fa-users",
                    "F_UrlAddress": null
                },
                {
                    "F_ModuleId": "10",
                    "F_ParentId": "0",
                    "F_EnCode": "CustomerManage",
                    "F_FullName": "金题库",
                    "F_Icon": "fa fa-newspaper-o",
                    "F_UrlAddress": null,
                    "F_Target": "",
                    "F_IsMenu": 0,
                    "F_AllowExpand": 1,
                    "F_IsPublic": 0,
                    "F_AllowEdit": null,
                    "F_AllowDelete": null,
                    "F_SortCode": 6,
                    "F_DeleteMark": 0,
                    "F_EnabledMark": 1
                },
                {
                    "F_ModuleId": "11",
                    "F_ParentId": "0",
                    "F_EnCode": "CustomerManage",
                    "F_FullName": "2018新版",
                    "F_Icon": "fa fa-inbox",
                    "F_UrlAddress": null
                },
                
            /************************************************
             * 级别：登录注册行为分析第二级菜单
             ************************************************/
                {
                    "F_ModuleId": "a11",
                    "F_ParentId": "a1",
                    "F_EnCode": "DataBaseLink",
                    "F_FullName": "游客相关数据",
                    "F_UrlAddress": "./dataHtml/login/loginPeople",
                    "F_Target": "iframe"
                },
                {
                    "F_ModuleId": "a22",
                    "F_ParentId": "a1",
                    "F_EnCode": "DataBaseLink",
                    "F_FullName": "注册相关数据",
                    "F_UrlAddress": "./dataHtml/login/loginPeople",
                    "F_Target": "iframe"
                },
                {
                    "F_ModuleId": "a55",
                    "F_ParentId": "a1",
                    "F_EnCode": "WeChatManage",
                    "F_FullName": "购买相关数据",
                    "F_UrlAddress": "./dataHtml/login/loginPeople",
                    "F_Target": "expand"

                },
                {
                    "F_ModuleId": "a33",
                    "F_ParentId": "a1",
                    "F_EnCode": "DataBaseLink",
                    "F_FullName": "功能使用数据",
                    "F_UrlAddress": "./dataHtml/login/loginPeople",
                    "F_Target": "iframe"
                },
                {
                    "F_ModuleId": "a55",
                    "F_ParentId": "a1",
                    "F_EnCode": "DataBaseLink",
                    "F_FullName": "新版本切换旧版本数据",
                    "F_UrlAddress": "./dataHtml/login/loginPeople",
                    "F_Target": "iframe"
                },
                
                {
                    "F_ModuleId": "a77",
                    "F_ParentId": "a1",
                    "F_EnCode": "DataBaseLink",
                    "F_FullName": "旧版本切换新版本数据",
                    "F_UrlAddress": "./dataHtml/login/loginPeople",
                    "F_Target": "iframe"
                },
                {
                    "F_ModuleId": "a77",
                    "F_ParentId": "a1",
                    "F_EnCode": "DataBaseLink",
                    "F_FullName": "新旧页面使用情况",
                    "F_UrlAddress": "./dataHtml/login/loginPeople",
                    "F_Target": "iframe"
                },
//               {
//                  "F_ModuleId": "a77",
//                  "F_ParentId": "a1",
//                  "F_EnCode": "DataBaseLink",
//                  "F_FullName": "分流量",
//                  "F_UrlAddress": "./dataHtml/login/loginPeople",
//                  "F_Target": "iframe"
//              },
//               {
//                  "F_ModuleId": "a88",
//                  "F_ParentId": "a1",
//                  "F_EnCode": "DataBaseLink",
//                  "F_FullName": "切换旧版本",
//                  "F_UrlAddress": "./dataHtml/login/loginPeople",
//                  "F_Target": "iframe"
//              },
//               {
//                  "F_ModuleId": "a99",
//                  "F_ParentId": "a1",
//                  "F_EnCode": "DataBaseLink",
//                  "F_FullName": "注册相关数据",
//                  "F_UrlAddress": "./dataHtml/login/loginPeople",
//                  "F_Target": "iframe"
//              },
//               {
//                  "F_ModuleId": "a10",
//                  "F_ParentId": "a1",
//                  "F_EnCode": "DataBaseLink",
//                  "F_FullName": "游客相关数据",
//                  "F_UrlAddress": "./dataHtml/login/loginPeople",
//                  "F_Target": "iframe"
//              },
//              {
//                  "F_ModuleId": "a11",
//                  "F_ParentId": "a1",
//                  "F_EnCode": "DataBaseLink",
//                  "F_FullName": "购买相关数据",
//                  "F_UrlAddress": "./dataHtml/login/loginPeople",
//                  "F_Target": "iframe"
//              },
            /***********************************************
             *父级：功能使用数据第二级菜单
             ***********************************************/
                {
                    "F_ModuleId": "e2",
                    "F_ParentId": "a3",
                    "F_EnCode": "小题大做",
                    "F_FullName": "小题大做",
                    "F_UrlAddress":"./dataHtml/dataUse/dataUse",
                    "F_Target": "expand"
                },
                 {
                    "F_ModuleId": "e3",
                    "F_ParentId": "a3",
                    "F_EnCode": "功能点击分布",
                    "F_FullName": "功能点击分布",
                    "F_UrlAddress":"./dataHtml/dataUse/dataUse",
                    "F_Target": "expand"
                },
                 {
                    "F_ModuleId": "e4",
                    "F_ParentId": "a3",
                    "F_EnCode": "考前冲刺包",
                    "F_FullName": "考前冲刺包",
                    "F_UrlAddress":"./dataHtml/dataUse/dataUse",
                    "F_Target": "expand"
                },
                  {
                    "F_ModuleId": "e5",
                    "F_ParentId": "a3",
                    "F_EnCode": "不同掌握程度的考点点击",
                    "F_FullName": "不同掌握程度的考点点击",
                    "F_UrlAddress":"./dataHtml/dataUse/dataUse",
                    "F_Target": "expand"
                },
                {
                    "F_ModuleId": "e6",
                    "F_ParentId": "a3",
                    "F_EnCode": "直播回放",
                    "F_FullName": "直播回放",
                    "F_UrlAddress":"./dataHtml/dataUse/dataUse",
                    "F_Target": "expand"
                },
//              {
//                  "F_ModuleId": "e7",
//                  "F_ParentId": "a3",
//                  "F_EnCode": "错题反馈",
//                  "F_FullName": "错题反馈",
//                  "F_UrlAddress":"./dataHtml/dataUse/dataUse",
//                  "F_Target": "expand"
//              },
                {
                    "F_ModuleId": "e7",
                    "F_ParentId": "a3",
                    "F_EnCode": "填写考生信息",
                    "F_FullName": "填写考生信息",
                    "F_UrlAddress":"./dataHtml/dataUse/dataUse",
                    "F_Target": "expand"
                },
                {
                    "F_ModuleId": "e8",
                    "F_ParentId": "a3",
                    "F_EnCode": "答疑排行榜",
                    "F_FullName": "答疑排行榜",
                    "F_UrlAddress":"./dataHtml/dataUse/dataUse",
                    "F_Target": "expand"
                },
                {
                    "F_ModuleId": "e9",
                    "F_ParentId": "a3",
                    "F_EnCode": "学习报告",
                    "F_FullName": "学习报告",
                    "F_UrlAddress":"./dataHtml/dataUse/dataUse",
                    "F_Target": "expand"
                },
                {
                    "F_ModuleId": "e10",
                    "F_ParentId": "8",
                    "F_EnCode": "考前突击弹框",
                    "F_FullName": "考前突击弹框",
                    "F_UrlAddress":"./dataHtml/yunying/dataUse",
                    "F_Target": "expand"
                },
                {
                    "F_ModuleId": "e11",
                    "F_ParentId": "8",
                    "F_EnCode": "考前冲刺包弹框",
                    "F_FullName": "考前冲刺包弹框",
                    "F_UrlAddress":"./dataHtml/yunying/dataUse",
                    "F_Target": "expand"
                },
                {
                    "F_ModuleId": "e12",
                    "F_ParentId": "a3",
                    "F_EnCode": "错题反馈",
                    "F_FullName": "错题反馈",
                    "F_UrlAddress":"./dataHtml/dataUse/dataUse",
                    "F_Target": "expand"
                },
                {
                    "F_ModuleId": "e13",
                    "F_ParentId": "a3",
                    "F_EnCode": "答疑社区",
                    "F_FullName": "答疑社区",
                    "F_UrlAddress":"./dataHtml/dataUse/dataUse",
                    "F_Target": "expand"
                },
                {
                    "F_ModuleId": "e14",
                    "F_ParentId": "a3",
                    "F_EnCode": "考点速记",
                    "F_FullName": "考点速记",
                    "F_UrlAddress":"./dataHtml/dataUse/dataUse",
                    "F_Target": "expand"
                },
                {
                    "F_ModuleId": "e15",
                    "F_ParentId": "8",
                    "F_EnCode": "考过攻略弹框",
                    "F_FullName": "考过攻略弹框",
                    "F_UrlAddress":"./dataHtml/yunying/dataUse",
                    "F_Target": "expand"
                },
            /***********************************************
             *父级：功能行为分析第二级菜单
             ***********************************************/
                {
                    "F_ModuleId": "d1",
                    "F_ParentId": "4",
                    "F_EnCode": "功能点击对比数据",
                    "F_FullName": "功能点击对比数据",
                    "F_Icon": "fa fa-book",
                    "F_UrlAddress":"./dataHtml/userClick/userClick",
                    "F_Target": "expand"
                },
                {
                    "F_ModuleId": "d2",
                    "F_ParentId": "4",
                    "F_EnCode": "购买流程数据",
                    "F_FullName": "购买流程数据",
                    "F_Icon": "fa fa-book",
                    "F_UrlAddress":"./dataHtml/purchase/purchase",
                    "F_Target": "expand"
                },{
                    "F_ModuleId": "d3",
                    "F_ParentId": "4",
                    "F_EnCode": "章节练习流程数据",
                    "F_FullName": "章节练习流程数据",
                    "F_Icon": "fa fa-book",
                    "F_UrlAddress":"./dataHtml/moduleExam/moduleExam",
                    "F_Target": "expand"
                },{
                    "F_ModuleId": "d4",
                    "F_ParentId": "4",
                    "F_EnCode": "考点精讲",
                    "F_FullName": "考点精讲",
                    "F_Icon": "fa fa-book",
                    "F_UrlAddress":"./dataHtml/testingCentre/testingCentre",
                    "F_Target": "expand"
                },
           
            
            
            /***********************************************
             *父级：答疑社区流程第二级菜单
             ***********************************************/
                {
                    "F_ModuleId": "d1",
                    "F_ParentId": "5",
                    "F_EnCode": "提问转化率",
                    "F_FullName": "提问转化率",
                    "F_UrlAddress": "./dataHtml/questionCenter/questionCenter",
                    "F_Target": "iframe"
                },
                {
                    "F_ModuleId": "d2",
                    "F_ParentId": "5",
                    "F_EnCode": "抢答转化率",
                    "F_FullName": "抢答转化率",
                    "F_UrlAddress": "./dataHtml/questionCenter/questionCenter",
                    "F_Target": "iframe"
                },
                {
                    "F_ModuleId": "d3",
                    "F_ParentId": "5",
                    "F_EnCode": "抢答参与热衷度",
                    "F_FullName": "抢答参与热衷度",
                    "F_UrlAddress": "./dataHtml/questionCenter/questionCenter",
                    "F_Target": "iframe"
                },
                {
                    "F_ModuleId": "d4",
                    "F_ParentId": "5",
                    "F_EnCode": "社区使用效率",
                    "F_FullName": "社区使用效率",
                    "F_UrlAddress": "./dataHtml/questionCenter/questionCenter",
                    "F_Target": "iframe"
                },
                {
                    "F_ModuleId": "d5",
                    "F_ParentId": "5",
                    "F_EnCode": "提问详情",
                    "F_FullName": "提问详情",
                    "F_UrlAddress": "./dataHtml/questionCenter/questionCenter",
                    "F_Target": "iframe"
                },{
                    "F_ModuleId": "d1",
                    "F_ParentId": "6",
                    "F_EnCode": "试题和文章的使用情况",
                    "F_FullName": "试题和文章的使用情况",
                    "F_UrlAddress": "http://test-data.yzztech.com/dashboard/yingteng/#/",
                    "F_Target": "iframe"
                },
                /***********************************************
	             *父级：答疑社区流程第二级菜单
	             ***********************************************/
	            {
                    "F_ModuleId": "d1",
                    "F_ParentId": "9",
                    "F_EnCode": "功能点击分布",
                    "F_FullName": "功能点击分布",
                    "F_UrlAddress": "./dataHtml/function/functionClick",
                    "F_Target": "iframe",
               },
               {
                    "F_ModuleId": "d2",
                    "F_ParentId": "9",
                    "F_EnCode": "答题量",
                    "F_FullName": "答题量",
                    "F_UrlAddress": "./dataHtml/function/functionClick",
                    "F_Target": "iframe",
                },
                {
                    "F_ModuleId": "d3",
                    "F_ParentId": "9",
                    "F_EnCode": "收藏题量",
                    "F_FullName": "收藏题量",
                    "F_UrlAddress": "./dataHtml/function/functionClick",
                    "F_Target": "iframe",
                },
                {
                    "F_ModuleId": "d1",
                    "F_ParentId": "10",
                    "F_EnCode": "登录数据",
                    "F_FullName": "登录数据",
                    "F_UrlAddress": "./dataHtml/goldBank/goldBank",
                    "F_Target": "iframe",
                },
                {
                    "F_ModuleId": "d1",
                    "F_ParentId": "7",
                    "F_EnCode": "启动设备数据",
                    "F_FullName": "启动设备数据",
                    "F_UrlAddress": "./dataHtml/plansForm/plansForm",
                    "F_Target": "iframe"
                },
                {
                    "F_ModuleId": "d2",
                    "F_ParentId": "7",
                    "F_EnCode": "各渠道产品注册相关数据",
                    "F_FullName": "各渠道产品注册相关数据",
                    "F_UrlAddress": "./dataHtml/plansForm/plansForm",
                    "F_Target": "iframe",
                },
                {
                    "F_ModuleId": "d3",
                    "F_ParentId": "7",
                    "F_EnCode": "各渠道产品购买相关数据",
                    "F_FullName": "各渠道产品购买相关数据",
                    "F_UrlAddress": "./dataHtml/plansForm/plansForm",
                    "F_Target": "iframe",
                },
                
                //
                {
                    "F_ModuleId": "ten1",
                    "F_ParentId": "11",
                    "F_EnCode": "功能使用人数",
                    "F_FullName": "功能使用人数",
                    "F_UrlAddress": "./dataHtml/newdata/distribution",
                    "F_Target": "iframe",
                },
                {
                    "F_ModuleId": "ten2",
                    "F_ParentId": "11",
                    "F_EnCode": "功能点击分布",
                    "F_FullName": "功能点击分布",
                    "F_UrlAddress": "./dataHtml/newdata/distribution",
                    "F_Target": "iframe",
                },
                {
                    "F_ModuleId": "ten3",
                    "F_ParentId": "11",
                    "F_EnCode": "每日一练",
                    "F_FullName": "每日一练",
                    "F_UrlAddress": "./dataHtml/newdata/distribution",
                    "F_Target": "iframe",
                }
            ];
            var _html = "";
            $.each(data, function (i) {
                var row = data[i];
                if (row.F_ParentId == "0") {
                    if (i == 0) {
                        _html += '<li class="treeview active">';
                    } else {
                        _html += '<li class="treeview">';
                    }
                    _html += '<a href="#">'
                    _html += '<i class="' + row.F_Icon + '"></i><span>' + row.F_FullName + '</span><i class="fa fa-angle-left pull-right"></i>'
                    _html += '</a>'
                    var childNodes = $.learunindex.jsonWhere(data, function (v) { return v.F_ParentId == row.F_ModuleId });

                    if (childNodes.length > 0) {
                        _html += '<ul class="treeview-menu">';
                        $.each(childNodes, function (i) {
                            var subrow = childNodes[i];
                            var subchildNodes = $.learunindex.jsonWhere(data, function (v) { return v.F_ParentId == subrow.F_ModuleId });
                            _html += '<li>';
                            if (subchildNodes.length > 0) {
                                _html += '<a href="#"><i class="' + subrow.F_Icon + '"></i>' + subrow.F_FullName + '';
                                _html += '<i class="fa fa-angle-left pull-right"></i></a>';
                                _html += '<ul class="treeview-menu">';
                                $.each(subchildNodes, function (i) {
                                    var subchildNodesrow = subchildNodes[i];
                                    _html += '<li><a class="menuItem" data-id="' + subrow.F_ModuleId + '" href="' + subrow.F_UrlAddress +i+'.html">' + 
                                    		subchildNodesrow.F_FullName + '</a></li>';
                                });
                                _html += '</ul>';
                            } else {
                                _html += '<a class="menuItem" data-id="' + subrow.F_ModuleId + '" href="' + subrow.F_UrlAddress + i+'.html">' + subrow.F_FullName + '</a>';

                            }
                            _html += '</li>';
                        });
                        _html += '</ul>';
                    }
                    _html += '</li>'
                }
            });
            $("#sidebar-menu").append(_html);
            $("#sidebar-menu li a").click(function () {
                var d = $(this), e = d.next();
                if (e.is(".treeview-menu") && e.is(":visible")) {
                    e.slideUp(500, function () {
                        e.removeClass("menu-open")
                    }),
                    e.parent("li").removeClass("active")
                } else if (e.is(".treeview-menu") && !e.is(":visible")) {
                    var f = d.parents("ul").first(),
                    g = f.find("ul:visible").slideUp(500);
                    g.removeClass("menu-open");
                    var h = d.parent("li");
                    e.slideDown(500, function () {
                        e.addClass("menu-open"),
                        f.find("li.active").removeClass("active"),
                        h.addClass("active");

                        var _height1 = $(window).height() - $("#sidebar-menu >li.active").position().top - 41;
                        var _height2 = $("#sidebar-menu li > ul.menu-open").height() + 10
                        if (_height2 > _height1) {
                            $("#sidebar-menu >li > ul.menu-open").css({
                                overflow: "auto"
                            })
                        }
                    })
                }
                e.is(".treeview-menu");
            });
        }
    };
    $(function () {
        $.learunindex.load();
        $.learunindex.loadMenu();
        $.learuntab.init();
    });
})(jQuery);